package com.zy.controller;

import com.zy.utils.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @author LittleDesire
 * @description
 * @date 2022-04-07 周四 17:07
 * @since 17
 */
@RestController
@RequestMapping("/admin")
public class IndexController {
    @Autowired
    private JwtUtils jwtUtils;

    @RequestMapping("/login")
    public Map<String, String> login(String account, String password) {
        Map<String, String> map = new HashMap<>();
        if ("root".equalsIgnoreCase(account) && "root".equalsIgnoreCase(password)) {
            map.put("code", "200");
            map.put("msg", "成功");
            map.put("token", jwtUtils.getToken(null, 10));
        } else {
            map.put("code", "405");
            map.put("msg", "失败");
        }
        return map;
    }
    @RequestMapping("/check")
    public String check() {
        return "lcheck";
    }
    @RequestMapping("/add")
    public String add(HttpServletRequest req) {
        if (req.getHeader("token") == null) {
            return "无令牌";
        } else if (jwtUtils.verifyToken(req.getHeader("token"))) {
            return "add";
        }else {
            return "无令牌";
        }
    }
    @RequestMapping("/del")
    public String del() {
        return "del";
    }

    @RequestMapping("/ass")
    public String ass() {
        return "ass";
    }
}
